<?php  
//获取微信回调用户信息
$appid = "wxe4003f0ac5b4efca";  
$secret = "0a66c8461b9003a9de5c0f65b9d0fa41";  

$code = $_GET["code"];
$tablenum = $_GET["state"];  
$get_token_url = 'https://api.weixin.qq.com/sns/oauth2/access_token?appid='.$appid.'&secret='.$secret.'&code='.$code.'&grant_type=authorization_code';  

//获取access_taken网络请求    
$data = file_get_contents($get_token_url);  
$json_obj = json_decode($data,true);  
 
//根据openid和access_token查询用户信息  
$access_token = $json_obj['access_token'];  
$openid = $json_obj['openid'];  
$get_user_info_url = 'https://api.weixin.qq.com/sns/userinfo?access_token='.$access_token.'&openid='.$openid.'&lang=zh_CN';  

$res = file_get_contents($get_user_info_url);

//解析json  
$user_obj = json_decode($res,true);  
$_SESSION['user'] = $user_obj;    
// echo $res;  
// echo $user_obj;
// echo $res;
// print_r($user_obj);
// echo $tablenum;


$con = mysql_connect("bdm257152524.my3w.com","bdm257152524","ldl932096158");//连接数据库
mysql_query("SET NAMES 'utf8'");//数据库输出编码
// echo "----";
if (!$con)
{
	die('Could not connect: ' . mysql_error());
}
mysql_select_db("bdm257152524_db", $con);//打开数据库
//提交用户信息到数据库
$sqlUser = "insert into user (userName,userImg,tableNum) values ('".$user_obj["nickname"]."','".$user_obj["headimgurl"]."','.$tablenum.')";
//提交创建桌台信息到数据库
// $sqlTable = "insert into tables (tableNum,userId) values ('.$tablenum.','Content')";
mysql_query($sqlUser);
// mysql_query($sqlTable);
mysql_close(); //关闭MySQL连接
//跳转到其他参加人的扫描页
echo '<script>url="userEnd.html";window.location.href=url;</script>';
?>  